package com.chang.common.controller;

/**
 * @program: erp-api
 * @description:
 * @author: chang
 * @create: 2025-02-14 15h
 **/

import com.chang.common.bean.ResultBean;
import com.chang.common.ex.BusinessException;
import com.chang.common.ex.ValidateException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice//异常增强注解
public class GlobalExceptionController extends BaseController {
    /**
     * 捕获后端验证异常
     * @param e
     * @return
     */
    @ExceptionHandler(ValidateException.class)
    public ResultBean handlerValidationException(ValidateException e) {
        return fail("验证失败",e.getErrorMap());
    }

    @ExceptionHandler(BusinessException.class)
    public ResultBean handlerBusinessException(BusinessException e) {
        return fail("业务异常",e.getMessage());
    }
}
